package com.bruce.asurada.sso.service.impl;

import org.springframework.stereotype.Service;

import com.bruce.asurada.sso.service.SmsService;

import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
public class SmsServiceImpl implements SmsService {
    private static final Logger logger = LoggerFactory.getLogger(SmsServiceImpl.class);
    
    @Override
    public boolean sendVerificationCode(String phone, String code) {
        // 实际项目中这里会调用第三方短信服务API
        // 这里仅做模拟实现
        try {
            logger.info("向手机号: {} 发送验证码: {}", phone, code);
            SmsBlend smsBlend = SmsFactory.getSmsBlend("tx1"); 
            SmsResponse smsResponse = smsBlend.sendMessage(phone,code);
            logger.info("向手机号: {} 发送验证码返回结果: {}", phone, smsResponse);
            // 模拟短信发送延迟
            Thread.sleep(500);
            return true;
        } catch (Exception e) {
            logger.error("发送短信失败", e);
            return false;
        }
    }
}
